<template>
  <div class="rightbox" v-cloak>
    <h1>挂号级别</h1>
    <div class="add-box" style="width:650px;">
      <el-form ref="form" :model="form" label-width="110px">
        <el-form-item
          label="名称"
          prop="name"
          :rules="[
            { required: true, message: '不能为空', trigger: 'blur' }
          ]"
        >
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item
          label="价格"
          prop="price"
          :rules="[
            { required: true, message: '不能为空', trigger: 'blur' }
          ]"
        >
          <el-input style="width:60px" v-model="form.price"></el-input>
        </el-form-item>
        <el-form-item
          label="状态"
          prop="state"
          :rules="[
            { required: true, message: '不能为空', trigger: 'blur' }
          ]"
        >
          <el-radio v-model="form.state" label="1">启用</el-radio>
          <el-radio v-model="form.state" label="-1">禁用</el-radio>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit('form')">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import qs from 'qs'
export default {
  data () {
    return {
      form: {
        price: '',
        name: '',
        state: '1'
      }
    }
  },
  methods: {
    submit: function (form) {
      var that = this
      that.$refs[form].validate((valid) => {
        if (valid) {
          axios.post('/gp/Number/AddPost', qs.stringify({
            name: that.form.name,
            price: that.form.price,
            state: that.form.state
          })
          )
            .then((res) => {
              that.$pub.close()
              if (res.data.code === 0) {
                that.$pub.messageTwo(res.data.data, '提示')
                that.resetForm()
              } else {
                that.$pub.failcode(that, res.data.code, res.data.data)
              }
            })
            .catch(function () {
              that.$pub.catchbox(that)
            })
        }
      })
    },
    resetForm: function () {
      var that = this
      that.form.name = ''
      that.form.price = ''
    }
  },
  mounted () {
  }
}
</script>
